import numpy as np

from sklearn.metrics import f1_score, roc_auc_score, accuracy_score,precision_score,recall_score

def acc_metra(y_test, y_pred,label):
    from sklearn.metrics import f1_score, roc_auc_score, accuracy_score, precision_score, recall_score
    accuracy = accuracy_score(y_test, y_pred)
    precision = precision_score(y_test, y_pred, average='macro')
    recall = recall_score(y_test, y_pred, average='macro')
    f1 = f1_score(y_test, y_pred, average='macro')
    print(f'Accuracy: {accuracy}')
    print(f'precision: {precision}')
    print(f'Recall: {recall}')
    print(f'F1 Score: {f1}')
    from sklearn.metrics import classification_report
    from sklearn.metrics import confusion_matrix
    import matplotlib.pyplot as plt
    from sklearn.metrics import accuracy_score
    from sklearn.metrics import f1_score
    import seaborn as sn  #画图模块
    from sklearn.metrics import confusion_matrix
    def plot_matrix(y_true, y_pred, title_name):
        cm = confusion_matrix(y_true, y_pred)  # 混淆矩阵
        # annot = True 格上显示数字 ，fmt：显示数字的格式控制
        ax = sn.heatmap(cm, annot=True, fmt='g', xticklabels=label, yticklabels=label)
        # xticklabels、yticklabels指定横纵轴标签
        ax.set_title(title_name)  # 标题
        ax.set_xlabel('predict')  # x轴
        ax.set_ylabel('true')  # y轴
        plt.show()

    # 调用函数画图
    plot = plot_matrix(list(y_pred), list(y_test), 'example-confusion matrix')